<template>
    <div class="app-container">
      <el-form ref="form" :model="formData" label-width="200px">
        <el-form-item label="是否每日答题">
          <el-switch
              style="display: block; margin-top: 5px;"
              v-model="formData.everyDay"
              :active-value="1"
              :inactive-value="0"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="答题次数">
          <el-input type="number" v-model="formData.number" placeholder="请输入答题次数"></el-input>
          <span style="color: red;">-1表示不限答题次数</span>
        </el-form-item>
        <el-form-item label="判断题数量">
          <el-input type="number" v-model="formData.numberJudge" placeholder="请输入判断题数量"></el-input>
        </el-form-item>
        <el-form-item label="单选题数量">
          <el-input type="number" v-model="formData.numberSingle" placeholder="请输入单选题数据"></el-input>
        </el-form-item>
        <el-form-item label="多选题数量">
          <el-input type="number" v-model="formData.numberMany" placeholder="请输入多选题数量"></el-input>
        </el-form-item>
        <el-button type="success" @click="toSave()">保存配置</el-button>
      </el-form>
    </div>
</template>


<script setup>
    import {ref} from 'vue'
    import {post,get} from "@/utils/request";
    import {ElMessage} from "element-plus";

    const formData = ref({
      everyDay:0,
      number:0,
      numberJudge:0,
      numberSingle:0,
      numberMany:0,
    })
    const initData = () => {
      get('/configuration/information').then(res=>{
        if (res) {
          formData.value = res
        }
      })
    }
    const toSave = () => {
      post('/configuration/save',formData.value).then(res=>{
        if (res) {
          ElMessage({
            message: '配置成功',
            type: 'success'
          });
        }
      })
    }
    initData()
</script>
